/**
 * @以秒为单位更新时间,使用数组结构
 *
 * @author	 wangshikun <wangshikun2010@gmail.com>
 * @copyright	(c) 2012 wangshikun <wangshikun2010@gmail.com>
 * @license	http://www.opensource.org/licenses/mit-license.php The MIT License
 * @package	default
 * @subpackage	default
 */

#include <stdio.h>
#include <cs50.h>

struct time {
	int hours;
	int minutes;
	int seconds;
};
struct time timeUpdate(struct time now);

int main(int argc, char *argv[]) {
	struct time currentTime[5] = {
		{11, 59, 59},{12, 0, 0},{1, 29, 59},{23, 59, 59},{19, 12, 27}
	};

	for (int i=0; i<5; i++) {
		printf("时间是%.2d:%.2d:%.2d", currentTime[i].hours, currentTime[i].minutes, currentTime[i].seconds);

		currentTime[i] = timeUpdate(currentTime[i]);
		printf("下一秒是：%.2d:%.2d:%.2d\n", currentTime[i].hours, currentTime[i].minutes, currentTime[i].seconds);
	}
}

//以秒为时间更新单位
struct time timeUpdate(struct time now) {
	now.seconds++;

	if (now.seconds == 60) {
		now.seconds = 0;
		now.minutes++;
 
	
		if(now.minutes == 60) {
			now.minutes = 0;
			now.hours++;
		

			if (now.hours == 24) {
				now.hours = 0;
			}
		}
	}

	return now;
}
